import request from './request'

export const getCategories = (params) => {
  return request({
    url: '/categories',
    method: 'get',
    params
  })
}

export const getCategory = (id, sel) => {
  return request({
    url: `/categories/${id}/attributes`,
    method: 'get',
    params: {
      sel: sel
    }
  })
}

export const getCategorieset = (id, attrname, attrsel) => {
  return request({
    url: `/categories/${id}/attributes`,
    method: 'post',
    data: {
      attr_name: attrname,
      attr_sel: attrsel
    }
  })
}

export const deleteCategory = (id, attrid) => {
  return request({
    url: `categories/${id}/attributes/${attrid}`,
    method: 'delete'
  })
}

export const addCategory = (id, attrid, attrname, attrsel) => {
  return request({
    url: `categories/${id}/attributes/${attrid}`,
    method: 'put',
    data: {
      attr_name: attrname,
      attr_sel: attrsel
    }
  })
}

export const selectCategory = (id, attrid, attrsel) => {
  return request({
    url: `categories/${id}/attributes/${attrid}`,
    method: 'get',
    params: {
      attr_sel: attrsel
    }
  })
}

export const addTagAttrVals = (id, attrid, attrname, attrsel, attrvals) => {
  return request({
    url: `categories/${id}/attributes/${attrid}`,
    method: 'put',
    data: {
      attr_name: attrname,
      attr_sel: attrsel,
      attr_vals: attrvals
    }
  })
}
